MAPS
Photo by Sara Scarpa on Unsplash
Well, it may be humorous to you, but it’s a very serious matter to the squirrels…
— Lisa Kleypas
df <- read.csv("archetypes/animal-rescues/animal-rescues.csv", header = TRUE, encoding = "UTF-8")
df
animal_by_boroughs <- df %>%
mutate(animal_group_parent = str_to_title(animal_group_parent)) %>%
count(borough_code, animal_group_parent, sort = TRUE) %>%
filter(animal_group_parent %in% c("Horse", "Cow", "Hamster", "Squirrel", "Lamb", "Sheep", "Snake", "Lizard", "Hedgehog", "Rabbit", "Ferret", "Fish", "Goat", "Pigeon", "Bull", "Tortoise")) %>%
ungroup()
as.data.frame(unique(animal_by_boroughs$animal_group_parent))
animal_by_boroughs
ltla_map <- st_read("archetypes/animal-rescues/local-authorities-lowertier-4-ltla-2019.geojson")
## Reading layer `LocalAuthorities-lowertier 4 LTLA-2019' from data source
## `C:\Users\jaybe\Desktop\kamino-dev\sources\10-maps\2-area\2-choropleth-facet\archetypes\animal-rescues\local-authorities-lowertier-4-ltla-2019.geojson'
## using driver `GeoJSON'
## Simple feature collection with 382 features and 9 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -7.557107 ymin: 49.76684 xmax: -7.556398 ymax: 49.76744
## Geodetic CRS: WGS 84
ltla_map
# to focus on london boroughs
# london_bk <- filter(background_map, RegionNation == "London")
london <- filter(ltla_map, RegionNation == "London")
# enrich spatial data with quantitative data for choropleth
london_animals <- london %>%
left_join(animal_by_boroughs, by = c("Lacode" = "borough_code")) %>%
# by filtering out, background will show
filter(!is.na(animal_group_parent))
head(london_animals, n = 10)
# this is used to plot an aesthetic background
center <- st_coordinates(st_centroid(london$geometry))
theme_opts <- theme(
text = element_text(family = "inconsolata", size = 16),
plot.title = element_text(color = "black", size = 16, face = "bold"),
plot.subtitle = element_text(color = "black", size = 12),
plot.caption = element_text(color = "#555555", size = 11),
plot.background = element_blank(),
axis.text = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background=element_rect(fill="white", colour="white"),
panel.border = element_blank(),
legend.position = "bottom",
legend.title = element_blank(),
)
fill_pallete <- c("#3B454A", "#31739C", "#21B3CD", "#FFD349", "#E85E26")
v1 <- ggplot(london_animals) +
# bottom layer as a cirle background
# geom_point(aes(x = center[1], y = center[2]), size = 150, shape = 21, fill = "#007EA7", stroke = 2) +
# border outline
geom_sf(data = london, aes(geometry = geometry), fill = "grey50", color = "white", size = 0.1) +
# the choropleth
geom_sf(data = london_animals, aes(geometry = geometry, fill = n), color = "white", size = 0.1) +
# color by bins from rescue count
scale_fill_stepsn(colors = fill_pallete, n.breaks = 5) +
# facet by animal group
facet_wrap(~animal_group_parent, ncol = 4) +
labs(
title = "Frequency of Rescues of Birds, Cats and Dogs in London from 2009-2021",
subtitle = NULL,
caption = NULL,
x = NULL,
y = NULL
) +
theme_minimal() +
theme_opts
girafe(ggobj = v1, width_svg = 16, height_svg = 13,
options = list(opts_sizing(rescale = TRUE, width = 1.0))
)